<extend name="Public/base" />
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="{:U('Index/index')}" data-original-title="首页"><i class="icon-home"></i>首页</a>
			<a class="current" href="{$post_url}">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br/>
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i></span>
						<h5>{$meta_title}</h5>
					</div>
					<div class="widget-content nopadding form-horizontal search-form">
						<div class="control-group" style="line-height:37px;">
							<label class="control-label"><button class="btn btn-info btn-focus">扫描纸质订单</button></label>
							<div class="controls">
							<form autocomplete="off">
								<input type="text" placeholder="纸质订单号" class="ui-wizard-content search-input" name="order_number" id="order_number" value="{:strip_tags(I('order_number'))}"  autocomplete="off" >
								<button class="btn btn-info" type="button" id="search_count" onclick="$('form').submit()"><i class="icon-search icon-white"></i></button>
							</form>
							</div>
						</div>
						<div id="gift_info_show" style="display:none;">
						<div class="control-group" style="line-height:37px;">
							<div class="controls">
								<span class="help-block blue" id="order_number_help" style="float:left; margin-right:20px; font-size:16px;" >
								</span>
							</div>
						</div>

						<div class="control-group">
							<div class="widget-content span10">
								<table class="table table-striped">
									<thead>
										<tr>
											<th nowrap="nowrap">编号</th>
											<th>订单号</th>
											<th>纸质订单号</th>
											<th>品类</th>
										</tr>
									</thead>	
									<tbody id="count_content"></tbody>
									<tbody>
										<tr>
											<td colspan='4'>
												<button class="btn btn-warning" type="button" onclick="gift_del();return false;">确定还礼</button>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var gift_id=0;
$(function (){
	//统计
	$('form').submit(function(){
		$('#search_count').prop('disabled', true);
		$.post("{:U('OrderGift/getOrderGiftInfo')}", $('form').serialize(), call_back, "json");
		return false;
		function call_back(data){
			if(data.status == 1){
				gift_id = data.info.gift_info.gift_id;
				var html_str = '活动：' + data.info.gift_info.activity_name + '<br>' +
					'用户：' + data.info.gift_info.customer_phone + '<br>' +
					'礼品：' + data.info.gift_info.present_name + '<br>' +
					'礼品数量：' + data.info.gift_info.gift_num + '<br>' +
					'换礼时间：' + data.info.gift_info.change_time + '<br>' +
					'操作人员：' + data.info.gift_info.member_name + '<br>';
					
				var html_content = '';
				$.each(data.info.gift_order_list,function(index,array){
					html_content += '<tr>';
					html_content += '<td class="taskStatus">' + (index+1) + '</td>';
					html_content += '<td class="taskStatus">' + array.order_id + '</td>';
					html_content += '<td class="taskStatus">' + array.paper_order + '</td>';
					html_content += '<td class="taskStatus">' + array.category_name + '</td>';
					html_content += '</tr>';
				})
					
				$('#gift_info_show').fadeIn(300);
				$('#order_number_help').html(html_str);
				$('#count_content').html(html_content);
			}else{
				tke_alert(data.info, 'alert-error', 2000);
				$('#gift_info_show').hide();
				$('#order_number_help').html('');
				$('#count_content').html('');
			}
			setTimeout(function(){
				$('#search_count').prop('disabled', false);
			}, 1000);
		}
	});
});
function gift_del(){
	if(!confirm('是否确定还礼？')){
		return false;
	}
	$('button').attr('disabled',true);
	var json_data = {
			gift_id : gift_id,
	};
	$.post("{:U('OrderGift/del')}", json_data, function(data) {
		if(data.status==1){
			tke_alert(data.info,'alert-success');
			setTimeout(function(){
			  if (data.url) {
					location.href=data.url;
				}else{
					location.reload();
				}
			},1500);
		} else {
			$('button').attr('disabled',false);
			tke_alert(data.info,'alert-error');
		}
		return false;
	}, "json");//JSON 是存储和交换文本信息的语法
}

$(document).ready(function(){
	$('#order_number').focus();//定位纸质订单光标
	
	$('.btn-focus').click(function(){
		$(this).parent().parent().find('input').val('');
		$(this).parent().parent().find('input').focus();
	})
	//导航高亮
	highlight_subnav("{:U('OrderGift/del')}");
});
</script>
</block>